package com.sanjiahantang.youjiarole.module.common.models.impl;

import android.content.Context;
import android.os.Handler;

import com.sanjiahantang.youjiarole.base.BaseBean;
import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.http.BaseDelegate;
import com.sanjiahantang.youjiarole.http.OkHttpClientManager;
import com.sanjiahantang.youjiarole.module.common.beans.CustomerBean;
import com.sanjiahantang.youjiarole.module.common.beans.DataBean;
import com.sanjiahantang.youjiarole.module.common.beans.DutyBean;
import com.sanjiahantang.youjiarole.module.common.beans.HelpBean;
import com.sanjiahantang.youjiarole.module.common.beans.MessageBean;
import com.sanjiahantang.youjiarole.module.common.beans.MessageNoticeCountBean;
import com.sanjiahantang.youjiarole.module.common.beans.MessageUseNoticeBean;
import com.sanjiahantang.youjiarole.module.common.beans.PersonBean;
import com.sanjiahantang.youjiarole.module.common.beans.PersonGoodsBean;
import com.sanjiahantang.youjiarole.module.common.beans.RoleStateBean;
import com.sanjiahantang.youjiarole.module.common.beans.StringBean;
import com.sanjiahantang.youjiarole.module.common.beans.UserBean;
import com.sanjiahantang.youjiarole.module.common.beans.UserOBean;
import com.sanjiahantang.youjiarole.module.common.models.IUserModel;
import com.sanjiahantang.youjiarole.module.complain.beans.ComplainBean;
import com.sanjiahantang.youjiarole.module.evaluate.beans.EvaGoodsBean;
import com.sanjiahantang.youjiarole.module.evaluate.beans.EvaServiceBean;
import com.sanjiahantang.youjiarole.module.me.address.beans.AddressBean;
import com.sanjiahantang.youjiarole.module.me.address.beans.AddressDetailBean;
import com.sanjiahantang.youjiarole.module.me.order.beans.OrderBean;
import com.sanjiahantang.youjiarole.module.me.order.beans.OrderGoods;
import com.sanjiahantang.youjiarole.module.me.order.beans.OrderListBean;
import com.sanjiahantang.youjiarole.module.me.scheme.beans.MeCaseOBean;
import com.sanjiahantang.youjiarole.module.me.scheme.beans.MeSchemeCaseListBean;
import com.sanjiahantang.youjiarole.module.me.scheme.beans.MeSchemeListBean;
import com.sanjiahantang.youjiarole.module.me.scheme.beans.SchemeBean;
import com.sanjiahantang.youjiarole.module.me.scheme.beans.SchemeListBean;
import com.sanjiahantang.youjiarole.module.money.beans.BankCardBean;
import com.squareup.okhttp.Request;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static android.R.attr.tag;


/**
 * Created by zy on 2017/9/4.
 */

public class UserModel implements IUserModel {

    @Override
    public void loadUserInfo(final Context context, Map<String, String> params, final CallBack<PersonBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/user/phone/personal/searchPersonalInfoForRole", params,
                new BaseDelegate.ResultCallback<PersonBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(PersonBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                }, true);
    }


    @Override
    public void getUserMessage(final Context context, Map<String, String> params,final CallBack<MessageBean> callBack) {
//        if (ConfigValue.isDebug) {
//            new Handler().postDelayed(new Runnable() {
//                public void run() {
//                    MessageBean model = new MessageBean();
//                    model.setCode(200);
//                    model.setMessage("成功");
//                    List<MessageBean.Data> data = new ArrayList<>();
//                    for (int i = 0; i < 10; i++) {
//                        MessageBean.Data msg = new MessageBean.Data();
//                        msg.setTitle("消息" + i);
//                        msg.setMessage("内容" + i * i);
//                        msg.setType(String.valueOf(i % 3));
//                        msg.setReaded(String.valueOf(i % 2));
//                        data.add(msg);
//                    }
//                    model.setData(data);
//                    callBack.onSuccess(model, context, tag);
//                }
//            }, 1000);
//            return;
//        }
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/system/phone/notice/searchNoticeForRole",
                params, new BaseDelegate.ResultCallback<MessageBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(MessageBean response, Object tag) {
                        callBack.onSuccess(response,context,tag);
//                        Log.e("11",response.getData());
                    }
                });
    }

    @Override
    public void getUseNoticeForCustomer(final Context context, Map<String, Object> params, final CallBack<MessageUseNoticeBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/system/phone/notice/saveSystemUseNoticeForRole",
                params, new BaseDelegate.ResultCallback<MessageUseNoticeBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(MessageUseNoticeBean response, Object tag) {
                        callBack.onSuccess(response,context,tag);
                    }
                });
    }

    @Override
    public void getSearchNoticeCountForCustomer(final Context context, Map<String, String> params, final CallBack<MessageNoticeCountBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/system/phone/notice/searchNoticeCountForRole",
                params, new BaseDelegate.ResultCallback<MessageNoticeCountBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(MessageNoticeCountBean response, Object tag) {
                        callBack.onSuccess(response,context,tag);
                    }
                });
    }
    @Override
    public void loadServiceEvaData(final Context context, final CallBack<EvaServiceBean> callBack) {

    }

    @Override
    public void loadGoodsEvaData(final Context context, final CallBack<EvaGoodsBean> callBack) {

    }

    @Override
    public void loadMeComplainList(final Context context, final int type, final CallBack<ComplainBean> callBack) {


    }

    @Override
    public void loadSchemeList(final Context context, Map<String, String> params, final CallBack<SchemeListBean> callBack) {

    }

    @Override
    public void loadSchemeDetail(final Context context, Map<String, String> params, final CallBack<SchemeBean> callBack) {

    }

    @Override
    public void loadSchemeListFirst(final Context context, Map<String, Object> params, final CallBack<MeSchemeListBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/user/phone/require/searchRequireForRole", params,
                new BaseDelegate.ResultCallback<MeSchemeListBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(MeSchemeListBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                }, true);
    }

    @Override
    public void getAddressList(final Context context, Map<String, String> params, final CallBack<AddressBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/user/role/address/searchRoleAddress", params,
                new BaseDelegate.ResultCallback<AddressBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(AddressBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                }, true);
    }

    @Override
    public void deleteAddress(final Context context, Map<String, String> params, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/user/role/address/deleteRoleAddress", params,
                new BaseDelegate.ResultCallback<BaseBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(BaseBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                }, true);
    }

    //保存收货地址
    @Override
    public void saveAddress(final Context context, Map<String, Object> params, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/user/role/address/saveRoleAddress", params,
                new BaseDelegate.ResultCallback<BaseBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(BaseBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }

    @Override
    public void loadAddressDetail(final Context context, Map<String, String> params, final CallBack<AddressDetailBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/user/role/address/indexRoleAddress", params,
                new BaseDelegate.ResultCallback<AddressDetailBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(AddressDetailBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                }, true);
    }

    @Override
    public void loadOrderList(final Context context, Map<String, String> params, final CallBack<OrderListBean> callBack) {
        if (ConfigValue.isDebug) {
            new Handler().postDelayed(new Runnable() {
                public void run() {
                    OrderListBean model = new OrderListBean();
                    model.setCode(200);
                    model.setMessage("成功");
                    List<OrderListBean.Data> data = new ArrayList<>();
                    for (int i = 0; i < 10; i++) {
                        OrderListBean.Data order = new OrderListBean.Data();
                        order.setOrder_sn("aaaa");
                        order.setStatus("un");
                        order.setOrder_sn("100100200");
                        List<OrderGoods> goodsList = new ArrayList<>();
                        for (int j = 0; j < 5; j++) {
                            OrderGoods goods = new OrderGoods();
                            goods.setGoods_name("名称名称名称名称名称名称名称");
                            goods.setGoods_number(String.valueOf(j));
                            goods.setGoods_price("1000");
                            goods.setGoods_thumb("data/shoplogo/1506347802070319578.png");
                            goodsList.add(goods);
                        }
                        order.setGoods(goodsList);
                        data.add(order);
                    }

                    model.setData(data);
                    callBack.onSuccess(model, context, tag);
                }
            }, 1000);
            return;
        }
    }

    @Override
    public void getCreatedOrder(final Context context, Map<String, String> params, final CallBack<OrderBean> callBack) {

    }

    //修改是否默认收货地址
    @Override
    public void editDefaultAddress(final Context context, Map<String, Object> params, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/user/role/address/saveRoleIsDefault", params,
                new BaseDelegate.ResultCallback<BaseBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(BaseBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }


    @Override
    public void dopersonData(final Context context, Map<String, String> params, final CallBack<UserBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/user/phone/role/findRoleInfoPhone", params,
                new BaseDelegate.ResultCallback<UserBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(UserBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });

    }


    //更新个人数据嘻嘻
    @Override
    public void updatePerson(final Context context, Map<String, Object> params, final CallBack<StringBean> callBack) {

        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/user/phone/role/updateRoleInfo",
                params, new BaseDelegate.ResultCallback<StringBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(StringBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }

    //获取职业信息
    @Override
    public void updateUserDuty(final Context context, Map<String, String> params, final CallBack<DutyBean> callBack) {


        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/system/dic/findDicByParentForPhone",
                params, new BaseDelegate.ResultCallback<DutyBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(DutyBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }

    @Override
    public void loadHelpList(final Context context, Map<String, Object> param, final CallBack<HelpBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/article/phone/searchArHelpInfoPhone",
                param, new BaseDelegate.ResultCallback<HelpBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(HelpBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }

    @Override
    public void loadHelpArticle(final Context context, Map<String, String> param, final CallBack<HelpBean.Item> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/article/phone/findArHelpByIdPhone",
                param, new BaseDelegate.ResultCallback<HelpBean.Item>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(HelpBean.Item response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }

    //提现明细
    @Override
    public void LoadMoneyDetail(final Context context, Map<String, Object> params, final CallBack<UserOBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/money/phone/role/findMoneyRecordInfo", params, new BaseDelegate.ResultCallback<UserOBean>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(UserOBean response, Object tag) {
                callBack.onSuccess(response, context, tag);

            }
        });

    }
   //我的物料管理
    @Override
    public void MyMeteriaManager(final Context context, Map<String, String> params, final CallBack<PersonGoodsBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/order/phone/searchGoodsManagement", params, new BaseDelegate.ResultCallback<PersonGoodsBean>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(PersonGoodsBean response, Object tag) {
                callBack.onSuccess(response, context, tag);

            }
        });
    }

    //提现
    @Override
    public void WithdrawalsMoney(final Context context, Map<String, String> params, final CallBack<UserBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/money/phone/role/withdrawals", params, new BaseDelegate.ResultCallback<UserBean>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(UserBean response, Object tag) {
                callBack.onSuccess(response, context, tag);

            }
        });
    }

    //载入客户列表
    @Override
    public void LoadCustomerList(final Context context, Map<String, Object> params, final CallBack<CustomerBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/user/phone/role/searchMyCustomerPhone", params, new BaseDelegate.ResultCallback<CustomerBean>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(CustomerBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }
     //我的项目合伙人
    @Override
    public void LoadCustomerMypartner(final Context context, Map<String, Object> params, final CallBack<UserOBean> callBack) {

        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/user/phone/role/findMyRoleInfo", params, new BaseDelegate.ResultCallback<UserOBean>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack .onFailure(e.getMessage());
            }

            @Override
            public void onResponse(UserOBean response, Object tag) {
                callBack.onSuccess(response, context, tag);

            }
        });

    }

    //查询银行卡信息
    @Override
    public void CheckBankInfo(final Context context, Map<String, Object> params, final CallBack<BankCardBean.Card> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/money/bank/role/searchBankCardDefault", params, new BaseDelegate.ResultCallback<BankCardBean.Card>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(BankCardBean.Card response, Object tag) {
                callBack.onSuccess(response, context, tag);

            }
        });

    }
    //添加银行卡列表暂时无接口
    @Override
    public void AddbankInfo(final Context context, Map<String, Object> params, final CallBack<UserOBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/money/bank/role/addBankCardInfo", params, new BaseDelegate.ResultCallback<UserOBean>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(UserOBean response, Object tag) {
                callBack.onSuccess(response, context, tag);

            }
        });


    }
    //查看银行卡列表
    @Override
    public void CheckBankListInfo(final Context context, Map<String, Object> params, final CallBack<BankCardBean.CardList> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/money/bank/role/searchBankCardInfo", params, new BaseDelegate.ResultCallback<BankCardBean.CardList>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(BankCardBean.CardList response, Object tag) {
                callBack.onSuccess(response, context, tag);

            }
        });
    }


    @Override
    public void findPassword(final Context context, Map<String, String> params, final CallBack<StringBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/user/phone/role/findPassword",
                params, new BaseDelegate.ResultCallback<StringBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(StringBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }

    @Override
    public void loadSchemeCaseList(final Context context, Map<String, String> params, final CallBack<MeSchemeCaseListBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/project/role/plan/searchProjectPlanInfoRole",
                params, new BaseDelegate.ResultCallback<MeSchemeCaseListBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(MeSchemeCaseListBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }
   //方案明细列表
    @Override
    public void loadSchemeCaseDetailList(final Context context, Map<String, String> params, final CallBack<MeCaseOBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/project/role/plan/searchProjectPriceForRole",
                params, new BaseDelegate.ResultCallback<MeCaseOBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(MeCaseOBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }

    @Override
    public void UpdataProjectInfo(final Context context, Map<String, String> map, final CallBack<StringBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/user/phone/role/updateRequireDesign",
                map, new BaseDelegate.ResultCallback<StringBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(StringBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }

    @Override
    public void addRequireSubcontractInfoByProject(final Context context, Map<String, Object> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/user/phone/require/addRequireSubcontractInfoByProject",
                param, new BaseDelegate.ResultCallback<BaseBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(BaseBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }

    @Override
    public void findMoneyRecordNumberInfo(final Context context, Map<String, Object> param, final CallBack<DataBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/money/phone/role/findMoneyRecordNumberInfo",
                param, new BaseDelegate.ResultCallback<DataBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(DataBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }

    @Override
    public void updateDefaultBankCard(final Context context, Map<String, String> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/money/bank/role/updateDefaultBankCard",
                param, new BaseDelegate.ResultCallback<BaseBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(BaseBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }

    public void findUserIdState(final Context context, Map<String, String> param, final CallBack<RoleStateBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/user/phone/role/findUserIdState",
                param, new BaseDelegate.ResultCallback<RoleStateBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(RoleStateBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }
}
